const config = require('../config/db-config');
const  Sequelize = require("sequelize");
const {QueryTypes,DataTypes} = require("sequelize");


var sequelizeObj = new Sequelize(//连接对象
   config.mysql.database,//数据库连接信息
   config.mysql.user,
   config.mysql.password,
   config.sequelize
);

const user = require('../model/user')(sequelizeObj,DataTypes)
const role = require('../model/role')(sequelizeObj,DataTypes)
const newsType = require('../model/newsType')(sequelizeObj,DataTypes)
const news = require('../model/news')(sequelizeObj,DataTypes)
role.hasMany(user,{
    foreignKey:'roleid',
    sourceKey:'id'
})
user.belongsTo(role,{
    foreignKey:'roleid',
    targetKey:'id'
})

newsType.hasMany(news,{
    foreignKey:'news_type_id',
    sourceKey:'id'
})
news.belongsTo(newsType,{
    foreignKey:'news_type_id',
    targetKey:'id'
})


news.belongsTo(user,{
    foreignKey:'userid',
    targetKey:'id'
})
module.exports = {user,role,newsType,news}